#include "b2UserData.h"

b2UserData::b2UserData(const char* my_name, int my_objecttype, void* my_object, bool draw_me) {//string name) {	
	
	b2ObjectType = my_objecttype; // must be 0, 1, 2 ...
	b2Object = my_object; // set the object pointer
	
	name = my_name; // set the name address (called in max)
	draw = draw_me; // set the draw flag

	ac = 0;	
	
	/* TODO : there must be a better way to o this void pointers to class magic ... */
	// call back to the object and create circular reference
	switch (b2ObjectType) {
		/* bodies */
		case e_b2BodyType:
			((b2Body*)b2Object)->SetUserData(this);
			break;
		
		/* shapes */
		case e_b2ShapeType:
			((b2Shape*)b2Object)->SetUserData(this);
			break;
		case e_b2PolygonShapeType:
		
			/* cycle through all polys */
			
			std::vector<b2PolygonShape*>* newPolys = (std::vector<b2PolygonShape*>*)my_object;
			nPolys = newPolys->size();
			
			for(int i = 0; i < nPolys; i++) {
				polys[i] = newPolys->at(i); // cause it's a pointer we use at (not [] operator)
				polys[i]->SetUserData(this);
			}
			
				
			break;
		case e_b2CircleShapeType:
			((b2CircleShape*)b2Object)->SetUserData(this);
			break;
		/* joints */	
		case e_b2JointType:
			((b2Joint*)b2Object)->SetUserData(this);
			break;
		case e_b2DistanceJointType:
			((b2DistanceJoint*)b2Object)->SetUserData(this);
			break;		
		case e_b2GearJointType:
			((b2GearJoint*)b2Object)->SetUserData(this);
			break;	
		case e_b2MouseJointType:
			((b2MouseJoint*)b2Object)->SetUserData(this);
			break;	
		case e_b2PrismaticJointType:
			((b2PrismaticJoint*)b2Object)->SetUserData(this);
			break;	
		case e_b2PulleyJointType:
			((b2PulleyJoint*)b2Object)->SetUserData(this);
			break;
		case e_b2RevoluteJointType:
			((b2RevoluteJoint*)b2Object)->SetUserData(this);
			break;
		default:
			//error("couldn't assign user data to object");
			break;
	}

}

